<?php

namespace App\Http\Controllers\admin\Patient;

use App\Http\Controllers\Controller;
use App\Http\Requests\StorePostRequest;
use App\Jobs\ProcessPlaynum;
use App\Logic\Es\EsService;
use App\Logic\reservation\EsHighlight;
use App\Models\Patient;
use Elasticsearch\ClientBuilder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Matrix\Exception;
use App\Logic\reservation\EsReservAtion;
class ReservationController extends Controller
{
    /**
     * @预约后台页面
     * @user wsg
     * @method get
     * @url http://www.healthcare.com/reservation/reservation_show_action
     * @data
     * @return \Illuminate\Http\Response
     */
    public function reservationShowAction(Request $request)
    {
        try {
            $userName=$request->get('patient');
            $ress  = Patient::with(['patientDoctor'])
                ->get()
                ->toArray();
            $data = EsHighlight::higHlight($userName);
            return  view('reservation/reservation',[
                'data' => $data,
                'ress' => $ress
            ]);
        }catch (Exception $exception){
            Log::info($exception->getMessage());
        }
    }
    /**
     * @搜索高亮显示
     * @user wsg
     * @method post
     * @url http://www.healthcare.com/reservation/reservation_create
     * @data
     * @return \Illuminate\Http\Response
     */
//    public function healthArticle(Request $request){
//
//
//
//        //返回管理员列表并传值
//        return view('reservation/reservation',['data'=>$data]);
//    }
    /**
     * @预约后台添加页面
     * @user wsg
     * @method get
     * @url http://www.healthcare.com/reservation/reservation_add
     * @data
     * @return \Illuminate\Http\Response
     */
    public function reservationAdd()
    {
        return  view('reservation/reservation_add');
    }

    /**
     * @预约后台执行添加
     * @user wsg
     * @method get
     * @url http://www.healthcare.com/reservation/reservation_add
     * @data
     * @return \Illuminate\Http\Response
     */
    public function reservationCreate(Request $request)
    {
        $request->validate([
            'patient' => 'required',//密码不能为空
            'visit_card' => 'required',
            'user_id' => 'required',
            'doctor_id' => 'required',
            'id_card' => 'required',
            'phone' => 'required',
            'sub_office' => 'required',
            'sub_type' => 'required',
            'sub_price' => 'required',
            'sub_status' => 'required',
            'address' => 'required',
            'sub_time' => 'required',
            'visit_time' => 'required',
        ], [
            'patient.required' => '密码不能为空',
            'visit_card.required' => '就诊卡号不能为空',
            'user_id.required' => '用户id格式不正确',
            'doctor_id.required' => '医生ID格式不正确',
            'id_card.required' => '身份证号不能为空',
            'phone.required' => '手机号不能为空',
            'sub_office.required' => '挂号科室不能为空',
            'sub_price.required' => '挂号价钱不能为空',
            'sub_status.required' => '挂号状态不能为空',
            'address.required' => '住址不能为空',
            'sub_time.required' => '预约时间不能为空',
            'visit_time.required' => '创建时间不能为空',
        ]);
        try {
            //获取除了"_token"和"s"以外的其他数据并赋值
            $data=$request->except("_token","s");
            //调用验证规则
//            ValiDateSout::create($data);
            //获取文件
            $file=$request->file('img');
            $res = EsReservAtion::esReserv($data,$file);
            return redirect("reservation/reservation_show_action");
        }catch (Exception $exception){
            Log::info($exception->getMessage());
        }
    }
    /**
     * @预约后台详情
     * @user wsg
     * @method get
     * @url http://www.healthcare.com/reservation/reservation_add
     * @data
     * @return \Illuminate\Http\Response
     */




}
